package controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import service.BookService;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.wordnik.swagger.annotations.Api;

import entity.Book;
import entity.UserExtInfo;

@Controller
@RequestMapping("/book")
@Api(value = "Book", description = "book service api", position = 1)
public class BookController {
	@Autowired
	private BookService bookService;
	
	@RequestMapping(value = "/{bookId}", method = RequestMethod.GET)
	public @ResponseBody Book getBook(@PathVariable String bookId) {
		return bookService.getBookById();
	}
	
	@RequestMapping(value = "/", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> insertBook(@RequestBody Book book) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("respCode", "0000");
		map.put("respDesc", "Success");
		return map;
	}
	
	@RequestMapping(value = "/book/{userId}", method = RequestMethod.GET)
	public @ResponseBody UserExtInfo getUserAllBook(@PathVariable String userId) {
		List<Book> books = new ArrayList<Book>();
		Book b = new Book();
		b.setBookId("B001");
		b.setBookName("swagger code");
		books.add(b);
		
		UserExtInfo userBook = new UserExtInfo();
		userBook.setUserId("1");
		userBook.setUserName("xiyt");
		userBook.setBooks(books);
		return userBook;
	}
	
	@RequestMapping(value = "/book/count/{userId}", method = RequestMethod.GET)
	public @ResponseBody int countBooks(@PathVariable String userId) {
		return 100;
	}
}
